<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>欢迎页面-X-admin2.2</title>
  <th:block th:include="include::header"/>
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
     onclick="location.reload()" title="刷新">
    <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
  </a>
</div>
<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-body ">
          <form class="layui-form layui-col-space5">
            <button class="layui-btn" id="demo1">
              下拉菜单
              <i class="layui-icon layui-icon-down layui-font-12"></i>
            </button>
            <div class="layui-inline layui-show-xs-block">
              <input type="text" name="re_cr_name" placeholder="请输入工艺名称" autocomplete="off"
                     class="layui-input"></div>
            <div class="layui-inline layui-show-xs-block">
              <button class="layui-btn" lay-submit="" lay-filter="search">
                <i class="layui-icon">&#xe615;</i>
              </button>
            </div>
          </form>
        </div>
        <div class="layui-card-header">
          <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
          </button>
          <button class="layui-btn" th:onclick="|xadmin.open('添加用户','@{/craft/requirement/add}',600,400)|"><i
                  class="layui-icon"></i>添加
          </button>
        </div>
        <div class="layui-card-body">
          <table class="layui-hide" id="userTable"></table>
        </div>
      </div>
    </div>
  </div>
</div>
</body>

<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData"> 获取选中行数据</button>
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-sm" lay-event="isAll"> 验证是否全选</button>
  </div>
</script>
<script type="text/html" id="re_cr_name">
  <a href="" style="color: blue"/>{{d.re_cr_name}}
</script>
<script>
  var tableIns;

  layui.use(['table','form'], function () {
    var table = layui.table;
    var form = layui.form;

    tableIns = table.render({
      elem: '#userTable',
      url: '/craft/requirement/list',
      method: "post",
      cols: [
        [
          {field: 're_id', title: '工艺要求编号 ', sort: true},
          {field: 're_cr_name', title: '工艺名称',align:'center',templet(d){
              var editJonit=`${ctx}/craft/manage/edit?cr_id=${d.re_id}`
              return `
            <a title="编辑" style="color: #1E9FFF" id="re_cr_id " onclick="xadmin.open('编辑','${editJonit}',600,400)" href="javascript:;">
        ${d.re_cr_name}</a></div>`}},
          {field: 're_requirements', title: '工艺要求',align:'center',templet(d){
              var editJonit=`${ctx}/craft/requirement/edit?re_id=${d.re_id}`
              return `
            <a title="编辑" style="color: #1E9FFF" id="re_id " onclick="xadmin.open('编辑','${editJonit}',600,400)" href="javascript:;">
        工艺要求</a></div>`}},
          {field: 're_add_time', title: '工艺要求添加时间 '},
          {field: 're_update_time', title: '工艺要求修改时间 '},
          {
            field: 'action', title: '操作', templet(d) {
              // 反引号 ，在里面写字符串可以换行
              //          取变量， ${}
              // var editUrl = ctx + "/user/edit?id="+d.id;
              var editUrl = `${ctx}/craft/requirement/edit?re_id=${d.re_id}`;

              return `
                                <div class="td-manage">
                                      <a title="编辑"  onclick="xadmin.open('编辑','${editUrl}',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a title="删除" onclick="craftDel(${d.re_id})" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                </div>
                            `
            }
          },
        ]
      ],
      page: true,
      parseData(res) {
        return {
          "code": res.success ? 0 : 500,
          "msg": res.msg,
          "count": res.data.total,
          "data": res.data.list
        }
      }
    });
//监听提交
    form.on('submit(search)',
            function (data) {
              tableIns.reload({
                where: {
                  re_cr_name: data.field.re_cr_name
                },
                page: {
                  curr: 1
                }
              })
              return false;
            });

  });

  function craftDel(re_id) {
    layer.confirm('确认要删除吗？', function (index) {
      $.ajax({
        url: ctx + '/craft/requirement/delete/' + re_id,
        type: 'delete',
        success(res) {
          if (res.success) {
            layer.msg("删除成功");
            setTimeout(function () {
              tableIns.reload();
            }, 500);
          }
        }
      })
    });


  }
</script>


</html>